package com.itljm.cxrMarket.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itljm.cxrMarket.entity.Orders;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itljm.cxrMarket.entity.dto.OrderItemProductsDTO;
import com.itljm.cxrMarket.entity.dto.OrderStatusCountDTO;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

public interface OrdersMapper extends BaseMapper<Orders> {
    // 新增订单
    int insertOrder(Orders order);
    List<Orders> findByStatusAndUpdateTimeBefore(Integer status, Date thresholdTime);
    // 更新订单状态
    int updateOrderStatus(Integer orderId, Integer status, Date updateTime);
    // 根据id查询订单
    Orders selectOrderById(Integer orderId);
    //分页查询所有订单
    List<Orders> selectAllOrdersPage(Page<Orders> page, @Param("ew") Wrapper<Orders> entityWrapper);
    // 根据用户id查询订单
    List<Orders> selectOrdersByUserId(Page<Orders> page, @Param("ew") Wrapper<Orders> entityWrapper, @Param("userId") Long userId);
    // 根据用户id统计订单状态数量
    OrderStatusCountDTO countOrderStatusByUserId(Long userId);
    // 根据用户id和订单状态查询订单
    List<Orders> selectOrdersByUserIdAndStatus(Page<Orders> page, Long userId, Integer status);

    // 根据订单id查询订单项
    List<OrderItemProductsDTO> selectOrders(Page<Orders> page, @Param("ew") Wrapper<Orders> entityWrapper);

    int isBuy(Long userId, Integer productId);
}




